package com.mxb.sqlsession;

import com.mxb.config.XMLConfigBuilder;
import com.mxb.model.Configuration;
import org.dom4j.DocumentException;

import java.beans.PropertyVetoException;
import java.io.InputStream;

/**
 * 类描述
 *
 * @Author: MaXiaobing
 * @Date: 2021/3/9 16:19
 */
public class SqlSessionFactoryBuilder {

    public SqlSessionFactory build(InputStream inputStream) throws DocumentException, PropertyVetoException {
        // 1、使用dom4j解析xml配置文件，将解析出来的内容封装到Configuration
        XMLConfigBuilder xmlConfigBuilder = new XMLConfigBuilder();
        Configuration configuration = xmlConfigBuilder.parseConfig(inputStream);

        // 2、创建SqlSessionFactory对象，作用：生产sqlSession会话对象（工厂模式）
        DefaultSqlSessionFactory defaultSqlSessionFactory = new DefaultSqlSessionFactory(configuration);

        return defaultSqlSessionFactory;
    }


}
